﻿@{
    ViewBag.Title = "MenuTree";
}
@section head
{
    <script src="@Url.Content("~/ScriptPlugin/ztree/js/jquery.ztree.core-3.5.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/ScriptPlugin/ztree/css/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
}
<div>
    <ul id="tree" class="ztree"></ul>
</div>
@section foot
{
    <script type="text/javascript">
        var treeData=@MvcHtmlString.Create(ViewBag.CatalogData);
        var rootData=@MvcHtmlString.Create(ViewBag.RootData);

        for(var i=0;i<treeData.length;i++)
        {
            rootData.push(treeData[i]);
        }
        var setting ={
		    data: {
			    simpleData: {
				    enable: true,
				    idKey:"Id",
				    pIdKey:"Pid"
			    },
			    key: {
				    name: "Name"
			    }
		    },
		    view: {
                fontCss: getFont,
				nameIsHTML: true
			},
            callback: {
				beforeClick: beforeClick
			}
		};
        function getFont(treeId,node)
        {
            return node.font ? node.font : {};
        }
        function beforeClick(treeId, treeNode, clickFlag)
        {

        }
        var zTree = $.fn.zTree.init($("#tree"), setting, rootData);

        function SaveData(index)
        {
            var nodes = zTree.getSelectedNodes();
            if(nodes.length==0)
            {
                K.Alert("请选择！");
            }
            if(!nodes[0].isRoot)
            {
                parent.K.layer.callback(index,nodes[0]);
                parent.K.layer.close(index);
            }
            else
            {
                K.Alert("不能选择根目录！")
            }
        }
    </script>
}